package base.hackathon.cupcake_cipher;

//Import required java libraries
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//Extend HttpServlet class
public class FeedConsumerServlet extends HttpServlet {

private String message;

public void init() throws ServletException
{
   // Do required initialization
   message = "Hello World";
}

public void doPost(HttpServletRequest request,
        HttpServletResponse response)
throws ServletException, IOException
{
	System.out.println(request);
	
	BufferedReader reader = request.getReader();
	StringBuilder sb = new StringBuilder();
	String line;
	while ((line = reader.readLine()) != null) {
		sb.append(line);
	}
	System.out.println(sb.toString());
	
   // Set response content type
   response.setContentType("text/html");

   // Actual logic goes here.
   PrintWriter out = response.getWriter();
   out.println("<h1>" + message + "</h1>");
}

public void doGet(HttpServletRequest request,
                 HttpServletResponse response)
         throws ServletException, IOException
{
	doPost(request, response);
}

public void destroy()
{
   // do nothing.
}
}